package com.guli.edu.scheduled;

import com.guli.edu.service.impl.StatisticsDailyServiceImpl;
import com.guli.edu.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author zxc
 * @date 2023/04/28 18:14
 **/
@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyServiceImpl statisticsDailyService;

//    @Scheduled(cron = "0/5 * * * * ?")
//    public void task01(){
//        System.out.println(new Date() + "正在执行~~~");
//    }

    // 定时任务（即，在每天凌晨一点都会去执行该任务 ：统计前一天网站的访问数据;）
    @Scheduled(cron = "0 0 1 * * ?")
    public void statisticsTask(){
        String date = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.getStatisticsByDay(date);
    }
}
